iT邦幫忙

2025 iThome 鐵人賽

DAY 11
1
AI & Data

動不動就要 ETL? 以Trino為例-淺談從資料倉儲到湖倉系列 第 11

Day 11 - Trino 地端架設與調參 (五)

  • 分享至 

  • xImage
  •  

11

Trino CLI 設置

在開始盡情使用 Trino 前,總需要有個媒介幫助你下指令,而 Trino CLI ( Command Line Interface ) 正是可以讓使用者從 Terminal 下達 SQL 指令,與 Trino server 互動、查詢資料的一種工具。

根據官方文檔,Trino CLI 是個自我執行的 JAR 檔,意即下載後可如一般程式直接執行 ( 如執行 .sh, .exe 檔 ),並在背景透過 https 與 coordinator 溝通,而後由 coordinator 分配查詢工作給 workers。

Trino CLI 的使用方式很簡單,透過 Terminal 將 JAR 檔載下來後,使用 htpasswd 加上新的 user / password ,然後就可以用 ./trino 方式直接執行 JAR 檔登入你的 Trino 並下達查詢指令。

# Download trino-cli (version 471)
curl -s -o trino https://repo1.maven.org/maven2/io/trino/trino-cli/471/trino-cli-471-executable.jar
chmod +x ./trino

# Add new user to password file
# Use admin as example
htpasswd -B -C 10 local/init/trino/coordinator/password.db admin

# login trino
./trino --server https://localhost:8443 \
        --truststore-path ./local/init/trino/certs/truststore.jks \
        --truststore-password=password \
        --user admin --password

多資料源查詢

當你成功登入 Trino 後,便可以下達 show catalogs 指令確認你的 Catalogs 都有正確設定,然後在下 show schemas from <your catalog> 指令確認該 catalog 的 schema 都顯示正確 :

# show catalogs
trino> show catalogs;

 Catalog
----------
 bigquery
 iceberg
 system
(3 rows)

# show schemas 
trino> show schemas from iceberg;

                 Schema
----------------------------------------
 datalakehouse_bronze_development
 datalakehouse_elt_bronze_development
 datalakehouse_elt_export_development
 datalakehouse_elt_gold_development

最後 SELECT 一下資料沒有問題後就大功告成,恭喜你成功的在地端架設了自己的 Trino 並完成不同資料源之 catalogs 設定及進行查詢,最後須注意在使用 Trino 查詢時要以 catalog.schema.table 的方式去表達來源 table:

trino> SELECT
           order_id,
           merchant_id,
           total_gross_amount,
           partitioned_at
       FROM
           iceberg.datalakehouse_elt_gold_production.order_sales
       WHERE
           _processed_at IS NOT NULL
       LIMIT 1;


    order_id   |   merchant_id| total_gross_amount|  partitioned_at                |
---------------+--------------+-------------------+--------------------------------+
67f48fxxxxac033|66b5d6xxxxx821|             4199.0| 2025-04-08 02:00:00.000000 UTC |

明日預告

系列文明日《部署與 CICD,Trino 在雲端 (一)》將帶你了解如何透過 Helm Chart 在 AWS EKS 上完成 Trino Cluster 的雲端部署,並說明背後在 EC2 節點上進行資源管理與配置的重點。

Know me more

My Linkedin: https://www.linkedin.com/in/benny0624/
My Medium: https://hndsmhsu.medium.com/


上一篇
Day 10 - Trino 地端架設與調參 (四)
下一篇
Day 12 - 部署與 CICD,Trino 在雲端 (一)
系列文
動不動就要 ETL? 以Trino為例-淺談從資料倉儲到湖倉29
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言